package com.easylinkin.linkappapi.elasticsearch.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * <p>
 *
 *
 * </p>
 *
 * @author XuGuoQing
 * @since 2020-04-23
 */
@Data
@AllArgsConstructor
public class DateSourceEnergyRecord extends Model<DateSourceEnergyRecord> {


    @JSONField(serialize=false)
    private static final long serialVersionUID = 1L;
    //当期
    @JSONField(serialize=false)
    private static final String  CURRENT = "current";
    //环比
    @JSONField(serialize=false)
    private static final String  MOM = "mom";
    private static final Logger LOGGER = LoggerFactory.getLogger(DateSourceEnergyRecord.class);





    /**
     * 数据id  
     */
    private String id;

    /**
     * 批次id
     */


    private Double dayEnergy;

    /**
     * 设备累计能源消耗
     */
    private Double sumEnergy;

    /**
     * 数据源id
     */
    private String dataSourceId;

    /**
     * 数据所属时间 年-月-日
     */

    private Date dataTime;


    /**
     * 能源类型
     */
    private String energyKind;

    /*
    jobId
     */
    private String jobId;
    /*
    计算规则Id
     */
    private String calcRuleId;
    /*
    计算规则名称
     */
    private String calcRuleName;
    /*
    calcCfgId
     */
    private String calcCfgId;
    /**
     * calcCfgName
     */
    private String calcCfgName;
    /*
    数据源名称
     */
    private String dataSource;
    /*
    能源类型
     */
    private String energyType;
    /*
    deviceCnt
     */
    private String deviceCnt;
    /*
    当日用电总量
     */
    private Double energyDay;
    /*
    当日环比改变量
     */
    private Double energyDayChangeRate;
    /*
    该星期用电总量
     */
    private Double energyWeek;
    /*
    该月用电总量
     */
    private Double energyMonth;
    /*
    七天用电总量
     */
    private Double energy7Day;
    /*
    七天改变量
     */
    private Double energy7DayChangeRate;
    /*
    三十天的总量
     */
    private Double energy30Day;
    /*
    每三十天改变量
     */
    private Double energy30DayChangeRate;
    /*
    计算结束时间
     */
    private String calcDate;
    /*
    创建时间
     */
    private String createTime;

    /*
    上班总人数
     */
    private Double onDutyPeopleNum;
    /*
    进入总人数
     */
    private Double totalIncount;
    /*
    出去总人数
     */
    private Double totalOutcount;
    /*
    设备编号
     */
    private String deviceCode;
    /*
    设备类型
     */
    private String deviceName;
    /*
    设备型号
     */
    private String uniqueMark;


    public DateSourceEnergyRecord(){
        super();
    }

    /**
     * 环比统计模型
     */
    @JSONField(serialize=false)
    MomStatisticModel  model;



    public void  initalMomStatisticModel(MomStatisticModel iniModel){

        model =iniModel;

    };

    /**
     * 时间段分类
     */
    public  String  haveStaticTime(){


        if(!dataTime.before(model.getCurrentBeginTime())&&!dataTime.after(model.getCurrentEndTime()))
        {
            return  CURRENT;
        }else if(!dataTime.before(model.getMomBeginTime())&&!dataTime.after(model.getMomEndTime()))
        {
            return  MOM;

        }else{
            return  "";
        }

    }

    public String haveDayTime() {
        String formatHMS = "yyyy-MM-dd";
        DateFormat sdf = new SimpleDateFormat(formatHMS);
//        return sdf.format(this.dataTime);
        return this.calcDate;
    }


    public String haveMonthTime() {
        String formatHMS = "yyyy-MM";
        DateFormat sdf = new SimpleDateFormat(formatHMS);
        String month = "";
        try {
            Date newDate = sdf.parse(this.calcDate);
            month = sdf.format(newDate);
        } catch (ParseException e) {
            LOGGER.error(e.getMessage(), e);
        }
//        return sdf.format(this.dataTime);
        return month;
    }





}
